limsProductReportTemplate.editPage = {

    getGridParam : function() {
        var _this = this;
        return {
            type : 'grid',
            id : 'lims-product-report-template-edit-list-grid',
            url : limsProductReportTemplate.baseUrl + '/queries/raw',
            service : 'limsProductReportTemplateServiceImpl',
            dbTable : 'T_LIMS_PRODUCT_REPORT_TEMPLATE',
            columns : limsProductReportTemplate.getEditListColumns(),
            deleteFormatter: function (row) {
                return row.templateCode;
            },
            onLoadSuccess : function(data) {
                if (!Gikam.isEmpty(data)) {
                    this.activeRowByIndex(0);
                } else {
                    Gikam.cleanCompData([ 'lims-report-client-product-edit-list-grid' ]);
                }
            },
            onRowActive : function(index, row) {
                Gikam.getAsyncComp('lims-report-client-product-edit-list-grid').done(function(grid) {
                    grid.refresh({
                        url : limsProductReportTemplate.clientProductUrl + '/queries',
                        requestData : {
                            reportTemplateId_EQ : row.id
                        }
                    });
                });
            },
            toolbar : [ {
                type : 'button',
                text : 'GIKAM.BUTTON.INSERT',
                icon : 'add',
                onClick : function() {
                    Gikam.preInsert({
                        modalTitle : 'GIKAM.BUTTON.INSERT',
                        fields : limsProductReportTemplate.getBaseInfoFormFields(),
                        url : limsProductReportTemplate.baseUrl
                    }).done(function(id) {
                        Gikam.getComp('lims-product-report-template-edit-list-grid').refresh();
                    });
                }
            }, {
                type : 'button',
                text : 'GIKAM.BUTTON.DELETE',
                icon : 'remove-row',
                onClick : function() {
                    Gikam.getComp('lims-product-report-template-edit-list-grid').deleteRows(limsProductReportTemplate.baseUrl);
                }
            } ]
        }
    },

    getBaseInfoTab : function() {
        var _this = this;
        return {
            type : 'tab',
            panels : [ {
                title : 'T_LIMS_REPORT_CLIENT_PRODUCT.SERVICE_NAME',
                items : [ {
                    type : 'grid',
                    id : 'lims-report-client-product-edit-list-grid',
                    service : 'limsReportClientProductServiceImpl',
                    dbTable : 'T_LIMS_REPORT_CLIENT_PRODUCT',
                    columns : limsProductReportTemplate.getClientProductListColumns(),
                    deleteFormatter: function (row) {
                        return row.productCode;
                    },
                    toolbar : [ {
                        type : 'button',
                        text : 'GIKAM.BUTTON.INSERT',
                        icon : 'add',
                        onClick : function() {
                            let row = Gikam.getComp('lims-product-report-template-edit-list-grid').getActivedRow();
                            if (Gikam.isEmpty(row)) {
                                return;
                            }
                            Gikam.preInsert({
                                modalTitle : 'GIKAM.BUTTON.INSERT',
                                fields : limsProductReportTemplate.getClientProductFormFields(),
                                disableNotEmptyValidate: true,
                                url : limsProductReportTemplate.clientProductUrl,
                                param : {
                                    reportTemplateId : row.id
                                }
                            }).done(function(id) {
                                Gikam.getComp('lims-report-client-product-edit-list-grid').refresh();
                            });
                        }
                    }, {
                        type : 'button',
                        text : 'GIKAM.BUTTON.DELETE',
                        icon : 'remove-row',
                        onClick : function() {
                            Gikam.getComp('lims-report-client-product-edit-list-grid').deleteRows(limsProductReportTemplate.clientProductUrl);
                        }
                    } ]
                } ]
            } ]
        }
    },

    create : function() {
        var _this = this;
        Gikam.create('layout', {
            id : 'lims-product-report-template-edit-list-layout',
            renderTo : workspace.window.$dom,
            west : {
                width : '50%',
                items : [ this.getGridParam() ]
            },
            center : {
                items : [ this.getBaseInfoTab() ]
            }
        });
    },

    init : function() {
        this.create();
    }
};
